<%@ page import="com.apexedu.portal.constant.Constants" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setAttribute("basePath", request.getContextPath());
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title><%=Constants.ProjectInfo.PROJECT_NAME%>
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="${basePath}/resources/css/mh.sdyz.css" rel="stylesheet">
    <link href="${basePath}/resources/ui/bootstrap/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${basePath}/resources/ui/js/jquery-1.10.2.min.js"></script>
    <script src="${basePath}/resources/js/mh.sdyz.index.js" type="text/javascript"></script>
    <script src="${basePath}/component/layer/layer.js" type="text/javascript"></script>
    <!--分页start-->
    <script type="text/javascript" src="${basePath}/resources/js/common.js"></script>
    <script type="text/javascript" src="${basePath}/component/jquery.pagination/jquery.pagination.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="${basePath}/component/jquery.pagination/pagination.css" />
    <!--分页end-->
    <style>

        #contentSub{
            text-align:left;
            background: #fff none repeat scroll 0 0;
            padding: 5px;
        }
    </style>

</head>
<body>
<div id="main">
    <input type="hidden" id="choosed" value="1"/>
    <jsp:include page="../left.jsp"/>
    <div id="right">
        <jsp:include page="../head.jsp"/>
        <form name="ysform" method="get">
            <input type="hidden" name="formname" value="ysform"/>
            <input type="hidden" name="state" value="1"/>
            <input type="hidden" name="gjz"  value="${gjz}"/>
            <input type="hidden" name="currentPageno" id="yspager_currentPageno" value="${pager.currentPageno }"/>
            <input type="hidden" name='eachPageRows' id='yspager_eachPageRows' value="${pager.eachPageRows }"/>
        <div id="contentSub">
            <h4>消息列表</h4>
            <table class="table table-bordered table-hover table-striped">
                <tr>
                    <th width="60px;">阅读状态</th>
                    <th width="60px;">处理状态</th>
                    <th>标题</th>
                    <th width="140px;">时间</th>
                    <th width="140px;">来源</th>
                </tr>

                <c:forEach items="${messageList}" var="message">
                    <tr>
                        <td class="jp_readStatus">
                            <c:if test="${message.zt=='unread'}">
                                <span class="label label-info">未读</span>
                            </c:if>
                            <c:if test="${message.zt=='read'}">
                                <span class="label label-success">已读</span>
                            </c:if>
                        </td>
                        <td>
                            <c:if test="${message.clzt==1}">
                                <span class="label label-info">待处理</span>
                            </c:if>
                            <c:if test="${message.clzt==3}">
                                <span class="label label-success">已处理</span>
                            </c:if>
                        </td>

                        <td>
                            <a href="javascript:void(0);" onclick="readMessage('${message.wid}','${message.url}',this)">${message.bt}</a>
                        </td>
                        <td>
                            <fmt:formatDate value="${message.sj}" pattern="yyyy-MM-dd HH:mm:ss"/>
                        </td>
                        <td>
                            <c:if test="${message.ly=='portal'}">系统消息</c:if>
                            <c:if test="${message.ly!='portal'}">${message.lymc}</c:if>
                        </td>
                    </tr>
                </c:forEach>

            </table>
            <!-- 分页 -->
            <div class="pagination" style="padding-top: 50px;">
                <div id="pagelist" align="center">
                    ${pager.postToolBar }
                </div>
                <br/>
            </div>
            <div class="left_low"></div>
            <!-- 分页部分 -->
            <div style="clear:both"></div>
        </div>

        <jsp:include page="../foot.jsp"/>
    </div>
</div>
</form>
<script>
    function readMessage(messagewid,url,obj){
        var $obj = $(obj).parents("tr").find(".jp_readStatus");
        if($obj.html().indexOf("未读")>=0){
            $obj.html("<span class=\"label label-success\">已读</span>");
            unreadCountJianYi();
        }

        if(url==""){
            layer.open({
                type: 2,
                title: '消息详情',
                shadeClose: true,
                shade: 0.8,
                area: ['600px', '450px'],
                content: '/s/m/detail/' +messagewid
            });
        }else{
            $.post("/s/m/read/"+messagewid,function(result){
                //layer.confirm('是否前往['+url+']?', {icon: 3, title:'提示'}, function(index){
                    window.open(url);
                    layer.close(index);
               // });
            });
        }

    }

    //未读数字减1
    function unreadCountJianYi(){
        var $div = $("#unreadMessage");
        var count = $div.html();
        $("#unreadMessage").html(count-1);
    }
</script>
</body>
</html>
